import QtQuick 2.0

Image {
    id: img
    source: gameover ? "qrc:/images/long_05.png" : "qrc:/images/long_0" + String(index) + ".png"

    property bool isJump: false
    property real speed: 0
    property real aspeed: 0

    property real groundposY: 436   // 地面位置
    property real index: 1

//    Rectangle{
//        anchors.fill: parent
//        color: "yellow"
//        opacity: 0.3
//    }

    function jump()
    {
        if(isJump) return
        isJump = true

        aspeed = 0
        speed = -20
    }

    function update(){
        if(index >= 3)
            index = 1
        else
            index++

        if(isJump)
        {
            aspeed += 0.1
            speed += aspeed
            img.y += speed

            if(speed == 0)
            {
                // top
                aspeed = 0
            }
        }
        if(img.y >= groundposY)
        {
            isJump = false
            img.y = groundposY
        }
    }
}
